package com.example.userdome.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.userdome.mapper.LikeMapper;
import com.example.userdome.pojo.Like;
import com.example.userdome.service.ILikeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

@Service
public class LikeServiceImpl {
    @Resource
    private LikeMapper likeMapper;

    public boolean addLike(Like like){
        int result=likeMapper.insert(like);
        return result>0;
    }
    public boolean cancelLike(Like like){
        QueryWrapper<Like> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("userid",like.getUserid()).eq("articleid",like.getArticleid());
        int result=likeMapper.delete(queryWrapper);
        return result>0;
    }
    public int countLikes(int articleid){
        QueryWrapper<Like> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("articleid",articleid);
        return likeMapper.selectCount(queryWrapper);
    }
}
